<!DOCTYPE html>
<html lang="en">
<title>企业储值卡管理</title>
<#import "/layout/layout.html" as body/>

<@body.page>
<div class="row wrapper border-bottom white-bg page-heading">
    <div class="col-lg-10">
        <h2>企业储值卡管理</h2>
        <ol class="breadcrumb">
            <li><a href="#">企业储值卡管理</a></li>
            <li class="active"><strong>员工列表</strong></li>
        </ol>
    </div>
</div>
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title overflow">
                    <h5 class="pull-left">【${(company.name)!}】 员工列表</h5>
                    <a href="${baseUrl}system/company/empl_add?companyId=${companyId}" class="btn btn-sm btn-primary pull-right" style="margin-left: 10px; ">新增员工</a>
                </div>
                <div class="ibox-content">
                    <div class="table-responsive">
                        <form  class="form-inline" role="form" id="form">
                            <div class="form-group">
                                <label for="name">员工姓名：</label>
                                <input class="form-control" type="text" id="name" name="name" value=""/>
                            </div>
                            <div class="form-group">
                                <label for="mobile">员工手机号：</label>
                                <input class="form-control" type="tel" id="mobile" name="mobile" value=""/>
                            </div>
                            <div class="form-group">
                                <label for="status">员工状态：</label>
                                <select class="form-control" id="status" name="stauts">
                                    <option value="">全部</option>
                                    <option value="0">正常</option>
                                    <option value="1">冻结</option>
                                    <option value="2">离职</option>
                                </select>
                            </div>
                            <a id="search" class="btn btn-outline btn-primary" style="margin-top: 5px">确认</a>
                        </form>
                        <hr style="width: 100%">
                        <table class="table table-hover table-center dataTables-example">
                            <thead>
                            <tr>
                                <th>员工ID</th>
                                <th>员工信息</th>
                                <th>绑定微信</th>
                                <th>用户ID</th>
                                <th>每月限额</th>
                                <th>本月余额</th>
                                <th>使用限制</th>
                                <th>历史消耗</th>
                                <th>状态</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody id="list">
                            </tbody>
                        </table>
                    </div>
                </div>
                <div class="ibox-footer overflow">
                    <div class="col-sm-12 padding-left-0">
                        <h4 class="pull-left">合计：<span id="count">0</span>位员工</h4>
                        <div id="copot-page" class="pull-right"></div>
                    </div>
                    <button type="button" id="go_back_list" class="btn btn-primary pull-left">返回企业列表</button>
                </div>
            </div>
        </div>
    </div>
    <!--企业公司Id-->
    <input type="hidden" id="companyId" value="${companyId}">
</div>
<script src="${baseUrl}js/main.js"></script>
<script>
    //返回列表
    $('#go_back_list').click(function () {
        window.location = "${baseUrl}system/company/list";
    });
    //搜索
    $("#search").click(function () {
        emplPage(1)
    });

    $(document).ready(function () {
        emplPage(1);
    });

    function emplPage(currentIndex) {
        var param = {
            "pageIndex": currentIndex,
            "pageSize": 10,
            "companyId": $("#companyId").val(),
            "name": $("#name").val(),
            "mobile": $("#mobile").val(),
            "status": $("#status").val()
        };
        if(param.status){

        }
        $.post("${baseUrl}system/company/emplList", param, function (result) {

            result = JSON.parse(result);
            //分页
            new Page({
                parent: $("#copot-page"),
                nowPage: currentIndex,
                pageSize: 10,
                totalCount: result.count,
                setting: {
                    defaultPage: 5,//默认显示可点击分页的个数
                    firstPageText: "首页",
                    prevPageText: "上一页",
                    nextPageText: "下一页",
                    lastPageText: "尾页"
                },
                callback: function (nowPage, totalPage) {
                    emplPage(nowPage);
                }
            });

            $("#count").text(result.count);

            var html = "";
            var status;
            var nickName;
            var userId;
            var limit ="";
            var monthlyLimit ="";
            var currentLeftAmount ="";
            var totalCostAmount;
            $.each(result.list, function (i, data) {
                if (data) {
                    if (data.status >= 0) {
                        if (data.status == 0) {
                            status = "正常"
                        }
                        if (data.status == 1) {
                            status = "冻结"
                        }
                        if (data.status == 2) {
                            status = "离职"
                        }
                    }
                    if(data.userId){
                        userId = data.userId;
                    } else {
                        userId ="未绑定微信";
                    }
                    if(data.nickName){
                        nickName = data.nickName;
                    } else {
                        nickName = "未绑定微信";
                    }
                    debugger
                    if(data.isBuyTypeLimit == 0){
                        limit ="";
                        //购买限制
                        if(data.limitTeamCourse == 1){
                            if(limit.length >0){
                                limit +="|"
                            }
                            limit += "团课";
                        }
                        if(data.limitSecretCourse == 1){
                            if(limit.length >0){
                                limit +="|"
                            }
                            limit += "私教";
                        }
                        if(data.limitCampCourse == 1){
                            if(limit.length >0){
                                limit +="|"
                            }
                            limit += "训练营";
                        }
                        if(data.limitSelfCourse == 1){
                            if(limit.length >0){
                                limit +="|"
                            }
                            limit += "自助";
                        }
                        if(data.limitVip == 1){
                            if(limit.length >0){
                                limit +="|"
                            }
                            limit += "会员";
                        }
                        if(data.limitValuedCard == 1){
                            if(limit.length >0){
                                limit +="|"
                            }
                            limit += "储值卡";
                        }
                    } else if(data.isBuyTypeLimit == 1){
                        limit = "无限制";
                    } else {
                        limit = "数据异常";
                    }
                    if(data.isMonthlyLimit == 1){
                        monthlyLimit = "无限制";
                        currentLeftAmount = "无限制";
                    } else if (data.isMonthlyLimit == 0){
                        monthlyLimit = data.monthlyLimit;
                        currentLeftAmount = data.currentLeftAmount;
                    }
                    if(data.totalCostAmount >0){
                        totalCostAmount = data.totalCostAmount;
                    } else {
                        totalCostAmount = "暂无数据";
                    }
                }
                html += "<tr><td>" + data.id + "</td>";
                html += "<td>" + data.name + "</br>" + data.mobile  + "</td>";
                html += "<td>" + nickName + "</td>";
                html += "<td>" + userId + "</td>";
                html += "<td>" + monthlyLimit + "</td>";
                html += "<td>" + currentLeftAmount + "</td>";
                html += "<td>" + limit + "</td>";
                html += "<td>" + totalCostAmount + "</td>";
                html += "<td>" + status + "</td>";
                html += "<td>";

                if(data.status !=2){
                    html += "<a href='${baseUrl}system/company/empl_add?companyId=" + data.companyId + "&id=" +data.id+ "' class='btn btn-default'><i class='fa fa-pencil'></i> 编辑</a>";
                }
                if (data.status == 0) {
                    html += '<a href="javascript:void(0)" onclick="lockEmpl(\'' + data.id + '\')" class="btn btn-default"><i class="fa fa-lock"></i> 冻结</a>';
                } else if (data.status == 1) {
                    html += '<a href="javascript:void(0)" onclick="unlockEmpl(\'' + data.id + '\')" class="btn btn-default"><i class="fa fa-unlock"></i>解冻</a>';
                }
                if(data.status !=2){
                    html += '<a href="javascript:void(0)" onclick="dimissionEmpl(\'' + data.id + '\')" class="btn btn-default"><i class="fa fa-ban"></i>离职</a>';
                }

                html += "</td>";
                html += "</tr>";
            });
            $("#list").html(html);

        });
    }

    /**
     * 冻结员工
     *
     * @param id 员工ID
     */
    function lockEmpl(id) {
        swal({
            title: "确定要冻结该员工吗?",
            type: "warning",
            showCancelButton: true,
            cancelButtonText: "容我三思！",
            confirmButtonText: "冻结!"
        }).then(function () {
            $.post("${baseUrl}system/company/lockEmpl?id=" + id, function (result) {
                if (result && result == "success") {

                    swal("冻结成功!", "页面即将重新加载,请稍后...", "success");
                    window.setTimeout(function () {
                        window.location.reload(true);
                    }, 1000);
                } else {
                    swal("错误!", result, "error");
                }
            });
        });
    }

    /**
     * 解冻员工
     *
     * @param id 员工ID
     */
    function unlockEmpl(id) {
        swal({
            title: "确定要解冻该员工吗?",
            type: "warning",
            showCancelButton: true,
            cancelButtonText: "容我三思！",
            confirmButtonText: "解冻!"
        }).then(function () {
            $.post("${baseUrl}system/company/unlockEmpl?id=" + id, function (result) {
                if (result && result == "success") {

                    swal("解冻成功!", "页面即将重新加载,请稍后...", "success");
                    window.setTimeout(function () {
                        window.location.reload(true);
                    }, 1000);
                } else {
                    swal("错误!", result, "error");
                }
            });
        });
    }
    /**
     * 离职员工
     *
     * @param id 员工ID
     */
    function dimissionEmpl(id) {
        swal({
            title: "确定要离职该员工吗?",
            type: "warning",
            showCancelButton: true,
            cancelButtonText: "容我三思！",
            confirmButtonText: "离职!"
        }).then(function () {
            $.post("${baseUrl}system/company/dimissionEmpl?id=" + id, function (result) {
                if (result && result == "success") {

                    swal("离职成功!", "页面即将重新加载,请稍后...", "success");
                    window.setTimeout(function () {
                        window.location.reload(true);
                    }, 1000);
                } else {
                    swal("错误!", result, "error");
                }
            });
        });
    }
</script>
</@body.page>
</html>